package my.li.zhcslandfront.controller;

import Vo.Land;
import land.LandFeignInterfance;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import page.PageBean;
import util.JsonResult;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.util.ArrayList;
import java.util.List;

@Controller
@RequestMapping("/land")
public class LandController {

    private LandFeignInterfance landFeignInterfance;

    @RequestMapping("/")
    public String test(HttpSession session){
        session.setAttribute("pagebean",new PageBean());
        session.setAttribute("lands",new ArrayList<Land>());
        return "area_manager";
    }
    @RequestMapping("/getAll")
    public String getAllMes(PageBean pageBean, HttpServletRequest request){
        HttpSession session = request.getSession();
        session.setAttribute("pagebean",pageBean);
//        List<Land> lands = landFeignInterfance.queryAll(pageBean);
        List<Land> lands = new ArrayList<>();
        session.setAttribute("lands",lands);
        return "area_manager";
    }


    @RequestMapping("/getById")
    @ResponseBody
    public String queryById(Land land){
//        landFeignInterfance.queryById(land);
        System.out.println("query : "+land);
      return "ok";
    }

    @RequestMapping("/add")
    @ResponseBody
    public JsonResult addLand(Land land ){
//        landFeignInterfance.addLand(land);
        //判断是否存在如果存在则进行修改
        System.out.println("add : "+land);
        return JsonResult.successWithoutData();
    }


    @RequestMapping("area_add")
    public String edit(Land land){

        System.out.println("修改操作: "+land);
        //查询进行数据回显
//        List<Land> lands = landFeignInterfance.queryById(land);
//        if(lands!=null && lands.size() == 1){
//            if(landFeignInterfance.updateLand(land)){
                return "area_add";
//            }else {
//                return "area_manager";
//            }
//        }else {
//            return "area_manager";
//        }
    }

    @RequestMapping("deleteById")
    @ResponseBody
    public JsonResult deleteByLandId(Land land){

        System.out.println("deletByLandId: "+land);
//        if(landFeignInterfance.deletLadn(land)){
            return JsonResult.successWithoutData();
//        }else {
//            return JsonResult.failed("失败");
//        }

    }



}
